#ifndef __GGEAR_CALLOCATOR_H
#define __GGEAR_CALLOCATOR_H

#include <new>
#include "ggear_types.h"

namespace ggear
{
	namespace glb
	{
		template<class _Tx>
		class Allocator
		{
		public:
			//Default constructor
			Allocator(){}

			//Destructor
			~Allocator(){}

			//Allocate new block of storage
			_Tx* Allocate(u32 _num)
			{
				return (_Tx*) ::operator new (sizeof(_Tx) * _num);
			}

			//Release previously allocated block of storage
			void Deallocate(_Tx* _ptr)
			{
				::operator delete (_ptr);
			}

			//Construct new T object
			void Construct(_Tx* _ptr, const _Tx& _ref)
			{
				new ((void*)_ptr) _Tx(_ref);
			}

			//Destroy an T object
			void Destroy(_Tx* _ptr)
			{
				_ptr->~_Tx();
			}

			//Return maximum number of T could be allocated
			u32 MaxSize() const
			{
				return ((u32)0xFFFFFFFF / sizeof(_Tx));
			}

			//Return address of allocated T
			u32 Address(const _Tx& _ref)
			{
				return &_ref;
			}

		public:
			//Change from CAllocator<T> to CAllocator<U>
			template<typename U>
			struct Rebind 
			{	
				typedef Allocator<U> Other;	
			};
		};
	}
}

#endif